//
//  RevealViewController.m
//  SliderPro
//
//  Created by sendInfo on 2014-04-03.
//  Copyright (c) 2014年 sendInfo. All rights reserved.
//

#import "RevealViewController.h"
#import "FrontViewController.h"
#import "RevealController.h"
#import "AppDelegate.h"
#import "HomeBoard.h"
#import "CartBoard.h"
#import "FanliManBoard.h"
#import "GuiderBoard.h"
#import "IntroBoard.h"


@interface RevealViewController ()<UITableViewDataSource,UITableViewDelegate>{


    UITableView *_table;
    UINavigationController *_currentNav;
    NSArray *_dataArr;
    NSArray *_imgArr;

}

@end

@implementation RevealViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    VIEW_BACKGROUND;
    self.navigationBarShown = NO;
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, self.bounds.size.width, self.bounds.size.height-40) style:UITableViewStylePlain];
    _table.backgroundColor = [UIColor clearColor];
    _table.separatorColor = [UIColor clearColor];
    _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    _table.scrollEnabled = NO;
    _table.dataSource = self;
    _table.delegate = self;
    UIImageView *bgimg = [[UIImageView alloc] initWithFrame:self.bounds];
    bgimg.image = [UIImage imageNamed:@"home-bg"];
    [self.view addSubview:bgimg];
    [self.view sendSubviewToBack:bgimg];

    _table.tableFooterView = [UIView new];
    [self.view addSubview:_table];
    _imgArr = @[[UIImage imageNamed:@"menu-home"],[UIImage imageNamed:@"menu-cart"],[UIImage imageNamed:@"menu-person"],[UIImage imageNamed:@"menu-manu"],[UIImage imageNamed:@"menu-help"]];
    
}

- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
     AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    if (app.isNeedSlider) {
        
        if (_currentNav) {
            
            
            [app.viewController setFrontViewController:_currentNav animated:NO];
        }
    }else{
    
        
    }
    
}
- (void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];

    
}
- (void)makeOrder:(UIBarButtonItem*)sender{
    

//    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    
//    if (![app.viewController.frontViewController isKindOfClass:[FrontViewController class]]) {
//        
//        
//        AppointmentVC *frvc = [[AppointmentVC alloc] initWithNibName:nil bundle:nil];
//        
//        
//        LSNVController *navigationController = [[LSNVController alloc] initWithRootViewController:frvc];
//        
//        [app.viewController setFrontViewController:navigationController animated:NO];
//    }

    

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _imgArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 80;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellID = @"CELLID";
    UITableViewCell *cell = nil;
    cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.backgroundColor = [UIColor clearColor];
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor = SET_COLORS(38.f, 97.f, 182.f);
        
        UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 70, 70)];
        imgv.image = _imgArr[indexPath.row];
        [cell addSubview:imgv];
        
       
        
    }
    
    
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

    
    BeeUIStack *navigationController;

    
    if (indexPath.row==0) { //首页
        
        if (![app.viewController.frontViewController isKindOfClass:[HomeBoard class]]) {
            
            
            HomeBoard *frvc = [[HomeBoard alloc] initWithNibName:nil bundle:nil];
            
            navigationController = [[BeeUIStack alloc] initWithRootViewController:frvc];
            
            [app.viewController setFrontViewController:navigationController animated:NO];
            
        }
        
    }else if (indexPath.row == 1){
    
        if (![app.viewController.frontViewController isKindOfClass:[CartBoard class]]) {
            
            
            CartBoard *frvc = [[CartBoard alloc]init];
            
            navigationController = [[BeeUIStack alloc] initWithRootViewController:frvc];
            
            [app.viewController setFrontViewController:navigationController animated:NO];
            
        }
    
    }else if (indexPath.row == 2){
    
        if (![app.viewController.frontViewController isKindOfClass:[HomeBoard class]]) {
            
            
            HomeBoard *frvc = [[HomeBoard alloc] initWithNibName:nil bundle:nil];
            frvc.homeType = @"editinfo";
            
            navigationController = [[BeeUIStack alloc] initWithRootViewController:frvc];
            
            [app.viewController setFrontViewController:navigationController animated:NO];
            
        }
    }else if (indexPath.row == 3){
    
        if (![app.viewController.frontViewController isKindOfClass:[GuiderBoard class]]) {
            
            
            IntroBoard *frvc = [[IntroBoard alloc] initWithNibName:nil bundle:nil];
            
            navigationController = [[BeeUIStack alloc] initWithRootViewController:frvc];
            
            [app.viewController setFrontViewController:navigationController animated:NO];
            
        }
    
    }else if (indexPath.row == 4){
    
        
        if (![app.viewController.frontViewController isKindOfClass:[FanliManBoard class]]) {
            
            
            HomeBoard *frvc = [[HomeBoard alloc] initWithNibName:nil bundle:nil];
            frvc.homeType = @"fanli";
            
            navigationController = [[BeeUIStack alloc] initWithRootViewController:frvc];
            
            [app.viewController setFrontViewController:navigationController animated:NO];
            
        }
    
    }

    _currentNav = navigationController;
    
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
